package com.franciscogarrido.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.franciscogarrido.model.dto.CategoriaLangDto;

public class CategoriasLangDao {

	private SqlSessionFactory sqlSessionFactory;

	public CategoriasLangDao() {
		sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
	}

	public int contarCategorias(){
		SqlSession session = sqlSessionFactory.openSession();

		try {
			List<CategoriaLangDto> categorias = session.selectList("CategoriasLang_SQL.contar");
			session.commit();
			return categorias.size();
		} finally {
			session.close();
		}
	}
	
	public List<CategoriaLangDto> buscar() {
		SqlSession session = sqlSessionFactory.openSession();

		try {
			List<CategoriaLangDto> categoriasLang = session.selectList("CategoriasLang_SQL.buscar");
			session.commit();
			return categoriasLang;
		} finally {
			session.close();
		}
	}
}